<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证年龄</title>
    <style type="text/css">
        span{color: #ff0000; padding-left: 5px; font-size: 12px;}
    </style>
</head>

<body>
   年龄： <input id="age" type="text"/><span id="divAge"></span>
   <script  src="js/jquery-1.12.4.js"></script>
   <script>
       $(document).ready(function(){
           $("#age").blur(function(){
               var age = $(this).val();
               var $ageId = $("#divAge");
                var regAge = /^120$|^((1[0-1]|[1-9])?\d)$/m;
               if (regAge.test(age) == false) {
                   $ageId.html("年龄不正确，请重新输入");
                   return false;
               }
               $ageId.html("");
               return true;
           })
       })
   </script>
</body>
</html>
